package accs.model.io;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpHost;

import accs.model.UserPasswordPair;

public class ProxyReader {
	private UserPasswordReader reader;
	
	public ProxyReader(UserPasswordReader reader) {
		this.reader=reader;
	}
	
	public HttpHost read() throws IOException {
		UserPasswordPair pair=reader.read();
		if(pair==null) return null;
		return new HttpHost(pair.getUsername(),Integer.parseInt(pair.getPassword()));
	}
	
	public List<HttpHost> readAll() throws IOException {
		List<HttpHost> list=new ArrayList<HttpHost>();
		HttpHost proxy=null;
		
		while((proxy=read())!=null) {
			list.add(proxy);
		}
		
		reader.close();
		
		return list;
	}
}